//
//  AppDelegate+DTCAppService.m
//  BluetoothProject
//
//  Created by Kendama Chen on 17/8/16.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import <Bugly/Bugly.h>
#import "IQKeyboardManager.h"
#import "AppDelegate+DTCAppService.h"
#import "ApartWarningApi.h"
#import <Hyphenate/Hyphenate.h>
#import "DemoCallManager.h"
#import "XMSDK.h"
#import "IFlyMSC/IFlyMSC.h"
#import "XMLYAuthorize.h"
#import "ChatDemoHelper.h"

//#import "DTCMQTTManager.h"

//#import "Reachability.h"


@interface AppDelegate ()<XMReqDelegate>

@end

@implementation AppDelegate (DTCAppService)

- (void)setNetworkBaseConfig
{
    YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
    config.baseUrl = ServerURL;
    
}

- (void)setBuglyConfig
{
    [Bugly startWithAppId:@"3483911368"];
}

- (void)setHyphenate
{
//    //AppKey:注册的AppKey，详细见下面注释。
//    //apnsCertName:推送证书名（不需要加后缀），详细见下面注释。
    EMOptions *options = [EMOptions optionsWithAppkey:@"1149171121115130#nuwarobot"];
    options.apnsCertName = ApnsCertName;
    [[EMClient sharedClient] initializeSDKWithOptions:options];
    // 自动同意进群邀请
    [[EMClient sharedClient].options setIsAutoAcceptGroupInvitation:YES];
    // 自动同意好友申请
    [[EMClient sharedClient].options setIsAutoAcceptFriendInvitation:YES];
    // 初始化视频聊天管理类
    [DemoCallManager sharedManager];
    
    [ChatDemoHelper shareHelper];
}

// APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[EMClient sharedClient] applicationDidEnterBackground:application];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    application.applicationIconBadgeNumber = 0;
}

// APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[EMClient sharedClient] applicationWillEnterForeground:application];
}
//- (void)setMQTT
//{
//    [[DTCMQTTManager shareManagerWithDeleagate:self]connectToHost:@"testapi.ourslinks.com" port:1883];
//
//}




- (void)setWindowBaseConfig
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    [[IQKeyboardManager sharedManager]setEnable:YES];
    [[IQKeyboardManager sharedManager]setKeyboardDistanceFromTextField:100];
    
    [SVProgressHUD setAnimationDuration:2.0];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    
}

- (void)setXimalaya
{
    [[XMReqMgr sharedInstance] registerXMReqInfoWithKey:@"9875df9f34ebd18747c7caa47795c8e6" appSecret:@"bd1da827c19ab1f7ea4f3df247d3804a"] ;
    [XMReqMgr sharedInstance].delegate = self;

    //    [[XMLYAuthorize shareInstance] initWithAppkey:@"fbd4101289a69b8b05a655567572e466" appSecret:@"765290912022212ff9621ed888c09f79" appRedirectUri:@"https://api.ximalaya.com/openapi-collector-app/get_access_token" appPackageId:@"com.kendama.NuwaRobot" appName:@"NuwaRobotEx" delegate:self];
}

- (void)didXMInitReqOK:(BOOL)result
{
    NSLog(@"初始化喜马拉雅成功");
}

- (void)didXMInitReqFail:(XMErrorModel *)respModel
{
    NSLog(@"初始化喜马拉雅失败");
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    [[XMReqMgr sharedInstance] closeXMReqMgr];
}

- (void)setIFlyMSC;
{
    //设置sdk的log等级，log保存在下面设置的工作路径中
    [IFlySetting setLogFile:LVL_ALL];
    
    //    打开输出在console的log开关
    [IFlySetting showLogcat:NO];
    
    //设置sdk的工作路径
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [paths objectAtIndex:0];
    [IFlySetting setLogFilePath:cachePath];
    
    
    NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",@"5a33700d"];
    
    
    [IFlySpeechUtility createUtility:initString];
}


- (void)registerHuanXin:(UIApplication *)application
{
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        //注册推送, 用于iOS8以及iOS8之后的系统
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];
    } else {
        //注册推送，用于iOS8之前的系统
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }
}


@end
